#ifndef CACHE_H
#define CACHE_H

#include <QLinkedList>
#include <QMutex>
#include <QObject>

#define DEF_MAX_SIZE 3

class BufferCache : public QObject
{
private:
    struct Item {
        char* buff;
        int len;
        Item(char* buff, int len);
    };

    int mMaxSize;
    QMutex mLock;
    QLinkedList<Item> mBuffers;
    int mBufferCount;
    static BufferCache sInstance;

    explicit BufferCache(int maxSize = DEF_MAX_SIZE, QObject *parent = nullptr);

public:
    char* get(int len);
    void put(char* buff, int len);

    static BufferCache& instance();
};

#endif // CACHE_H
